package com.retail.system.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.system.common.domain.TShop;
import com.retail.system.server.service.ITShopService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 商品列表Controller
 * 
 * @author retail
 * @date 2024-02-25
 */
@RestController
@RequestMapping("/shop")
public class TShopController extends BaseController
{
    @Autowired
    private ITShopService tShopService;

    /**
     * 查询商品列表列表
     */
    @RequiresPermissions("shop:shop:list")
    @GetMapping("/list")
    public TableDataInfo list(TShop tShop)
    {
        startPage();
        List<TShop> list = tShopService.selectTShopList(tShop);
        return getDataTable(list);
    }

    /**
     * 导出商品列表列表
     */
    @RequiresPermissions("shop:shop:export")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TShop tShop)
    {
        List<TShop> list = tShopService.selectTShopList(tShop);
        ExcelUtil<TShop> util = new ExcelUtil<TShop>(TShop.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
    @RequiresPermissions("shop:shop:query")
    @GetMapping(value = "/{shopId}")
    public Result getInfo(@PathVariable("shopId") Long shopId)
    {
        return success(tShopService.selectTShopByShopId(shopId));
    }

    /**
     * 新增商品列表
     */
    @RequiresPermissions("shop:shop:add")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TShop tShop)
    {
        return toAjax(tShopService.insertTShop(tShop));
    }

    /**
     * 修改商品列表
     */
    @RequiresPermissions("shop:shop:edit")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TShop tShop)
    {
        return toAjax(tShopService.updateTShop(tShop));
    }

    /**
     * 删除商品列表
     */
    @RequiresPermissions("shop:shop:remove")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public Result remove(@PathVariable Long[] shopIds)
    {
        return toAjax(tShopService.deleteTShopByShopIds(shopIds));
    }
}
